package com.haoliang.spring.component.java.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Author zhaohaoliang
 * @Date 创建于 下午12:10 2019/3/10
 * @Description 请输入类的描述信息
 */
public class MacCondition implements Condition {
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获得bean工厂
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        // 获取类加载器
        ClassLoader classLoader = context.getClassLoader();
        // 获取环境
        Environment environment = context.getEnvironment();
        // 获取bean定义的注册类
        BeanDefinitionRegistry registry = context.getRegistry();
        // 获取资源加载器
        ResourceLoader resourceLoader = context.getResourceLoader();
        String osName = environment.getProperty("os.name");
        // 判断容器中是否包含bean
        if (registry.containsBeanDefinition("xuzhu")){
            System.out.println("容器中包含虚竹");
        }
        return osName.contains("Mac");
    }
}
